package grav;

import static mathUtils.VecMath.vecMag;
import static mathUtils.VecMath.vecScale;
import static mathUtils.VecMath.vecSub;
import processing.core.PApplet;
import tennos.Flake;

public class GravFlake extends Flake implements Gravitational {

	public GravFlake(PApplet p) {
		super(p);
	}
	public GravFlake(PApplet p, float m, float r, float px, float py, float vx, float vy) {
		super(p);
		mass = m;
		radius = r;
		s[0][0] = px;
		s[0][1] = py;
		s[1][0] = vx;
		s[1][1] = vy;
	}
	
	public float gravMass() {return mass;}
	public float gravRho() {return 0;}

	public float[] geeAt(float x[], float bigG) {
		float gee[] = x.clone();
		vecSub(gee, position(), gee);
		float r = vecMag(gee);
		vecScale(gee, -bigG*gravMass()/(r*r*r));
		return gee;
	}	
	public float[] geeAt(float x[]) {
		return geeAt(x, 1.0f);
	}
	
	public float[] geeForceOn(Gravitational a, float bigG) {
		float f[];
		f = geeAt(a.position());
		vecScale(f, a.gravMass());
		return f;
	}
	
	public void draw() {
		parent.stroke(250, 250, 250);
		parent.strokeWeight(0);
		parent.fill(150, 150, 150);
		parent.ellipse(position()[0], position()[1], radius/2, radius/2);
	}
}
